package cn.kongwg.juc;

import jdk.nashorn.internal.runtime.linker.LinkerCallSite;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author kongwg
 * @create 2021-04-30 21:36
 */
public class NoSafeDemo {
    public static void main(String[] args) {
        Map<String,String> map =new HashMap<>();
        for (int i = 0; i < 100; i++) {
            new Thread(() -> {
                map.put(Thread.currentThread().getName(), UUID.randomUUID().toString().substring(0, 8));
                System.out.println("map = " + map);
            }, String.valueOf(i).toString()).start();

        }
    }

    private static void cparraylist() {
        List<String> list = new CopyOnWriteArrayList();
        list.add("123");
        list.add("123");
        list.add("123");

        for (int i = 0; i < 300; i++) {
            new Thread(() -> {
                list.add(UUID.randomUUID().toString().substring(0, 8));
                System.out.println("list = " + list);
            }, String.valueOf(i)).start();
        }
    }

}
